home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Games / Pararena 1.3 / source / Parts ƒ / Dialogs.p next >
Encoding:
Text File  |  1991-05-15  |  11.8 KB  |  559 lines  |  [TEXT/PJMM]

  1. unit Dialogs;
  2.  
  3. interface
  4.     uses
  5.         Sound, Globals;
  6.  
  7.     var
  8.         soundWndo, speedWndo, physicsWndo: WindowPtr;
  9.  
  10.     procedure DoSound;
  11.     procedure DoSpeed;
  12.     procedure DoHelpPlay;
  13.     procedure DoHelpRules;
  14.     procedure DoPhysics;
  15.  
  16. implementation
  17.  
  18. {=================================}
  19.  
  20.     var
  21.         upRect, dnRect: Rect;
  22.  
  23. {=================================}
  24.  
  25.     procedure DoSound;
  26.         const
  27.             okayButton = 1;
  28.             cancelButton = 2;
  29.             soundOnRadio = 3;
  30.             soundOffRadio = 4;
  31.             soundCheck1 = 5;
  32.             soundCheck2 = 6;
  33.             soundCheck3 = 7;
  34.             soundCheck4 = 8;
  35.             soundCheck5 = 9;
  36.             userItem = 11;
  37.             userItem2 = 12;
  38.  
  39.         var
  40.             theDlgPtr: DialogPtr;
  41.             tempRect: Rect;
  42.             itemT, itemHit, i: Integer;
  43.             itemH: Handle;
  44.             tempStr: Str255;
  45.             tempBools: array[1..5] of Boolean;
  46.             exitDialog, tempSoundOn: Boolean;
  47.  
  48. {----------------}
  49.  
  50.         procedure DrawDefaultAndFrame;
  51.         begin
  52.             ForeColor(redColor);
  53.             GetDItem(theDlgPtr, userItem, itemT, itemH, tempRect);
  54.             FrameRect(tempRect);
  55.             GetDItem(theDlgPtr, userItem2, itemT, itemH, tempRect);
  56.             FrameRect(tempRect);
  57.             ForeColor(blackColor);
  58.             GetDItem(theDlgPtr, okayButton, itemT, itemH, tempRect);
  59.             PenSize(3, 3);
  60.             InsetRect(tempRect, -4, -4);
  61.             FrameRoundRect(tempRect, 16, 16);
  62.             PenNormal;
  63.         end;
  64.  
  65. {----------------}
  66.  
  67.         procedure UpdateChecks;
  68.             var
  69.                 i: Integer;
  70.         begin
  71.             for i := 1 to 5 do
  72.                 if (tempBools[i]) then
  73.                     begin
  74.                         GetDItem(theDlgPtr, i + soundCheck1 - 1, itemT, itemH, tempRect);
  75.                         SetCtlValue(ControlHandle(itemH), 1);
  76.                     end
  77.                 else
  78.                     begin
  79.                         GetDItem(theDlgPtr, i + soundCheck1 - 1, itemT, itemH, tempRect);
  80.                         SetCtlValue(ControlHandle(itemH), 0);
  81.                     end;
  82.         end;
  83.  
  84. {----------------}
  85.  
  86.         procedure UpdateRadios;
  87.             var
  88.                 i: Integer;
  89.         begin
  90.             if (tempSoundOn) then
  91.                 begin
  92.                     GetDItem(theDlgPtr, soundOnRadio, itemT, itemH, tempRect);
  93.                     SetCtlValue(ControlHandle(itemH), 1);
  94.                     GetDItem(theDlgPtr, soundOffRadio, itemT, itemH, tempRect);
  95.                     SetCtlValue(ControlHandle(itemH), 0);
  96.  
  97.                     for i := 1 to 5 do
  98.                         begin
  99.                             GetDItem(theDlgPtr, i + soundCheck1 - 1, itemT, itemH, tempRect);
  100.                             if (tempBools[i]) then
  101.                                 SetCtlValue(ControlHandle(itemH), 1)
  102.                             else
  103.                                 SetCtlValue(ControlHandle(itemH), 0);
  104.  
  105.                             HiliteControl(ControlHandle(itemH), 0);
  106.                         end;
  107.                 end
  108.             else
  109.                 begin
  110.                     GetDItem(theDlgPtr, soundOffRadio, itemT, itemH, tempRect);
  111.                     SetCtlValue(ControlHandle(itemH), 1);
  112.                     GetDItem(theDlgPtr, soundOnRadio, itemT, itemH, tempRect);
  113.                     SetCtlValue(ControlHandle(itemH), 0);
  114.  
  115.                     for i := 1 to 5 do
  116.                         begin
  117.                             GetDItem(theDlgPtr, i + soundCheck1 - 1, itemT, itemH, tempRect);
  118.                             SetCtlValue(ControlHandle(itemH), 0);
  119.                             HiliteControl(ControlHandle(itemH), 255);
  120.                         end;
  121.                 end;
  122.         end;
  123.  
  124. {----------------}
  125.  
  126.     begin
  127.         CenterDialog(soundDialID);
  128.         theDlgPtr := GetNewDialog(soundDialID, nil, Pointer(-1));
  129.         ShowWindow(theDlgPtr);
  130.         SetPort(GrafPtr(theDlgPtr));
  131.  
  132.         for i := 1 to 5 do
  133.             begin
  134.                 tempBools[i] := soundArray[i];
  135.                 if (tempBools[i]) then
  136.                     begin
  137.                         GetDItem(theDlgPtr, i + soundCheck1 - 1, itemT, itemH, tempRect);
  138.                         SetCtlValue(ControlHandle(itemH), 1);
  139.                     end
  140.                 else
  141.                     begin
  142.                         GetDItem(theDlgPtr, i + soundCheck1 - 1, itemT, itemH, tempRect);
  143.                         SetCtlValue(ControlHandle(itemH), 0);
  144.                     end;
  145.             end;
  146.         tempSoundOn := soundOn;
  147.  
  148.         UpdateChecks;
  149.         UpdateRadios;
  150.  
  151.         exitDialog := FALSE;
  152.         DrawDefaultAndFrame;
  153.  
  154.         repeat
  155.             ModalDialog(nil, itemHit);
  156.  
  157.             if (ItemHit = okayButton) then
  158.                 begin
  159.                     exitDialog := TRUE;
  160.                     soundOn := tempSoundOn;
  161.                     for i := 1 to 5 do
  162.                         soundArray[i] := tempBools[i];
  163.                 end;
  164.  
  165.             if (ItemHit = cancelButton) then
  166.                 exitDialog := TRUE;
  167.  
  168.             if (itemHit = soundOnRadio) then
  169.                 begin
  170.                     tempSoundOn := TRUE;
  171.                     UpdateRadios;
  172.                 end;
  173.  
  174.             if (itemHit = soundOffRadio) then
  175.                 begin
  176.                     tempSoundOn := FALSE;
  177.                     UpdateRadios;
  178.                 end;
  179.  
  180.             if ((itemHit >= soundCheck1) and (itemHit <= soundCheck5)) then
  181.                 begin
  182.                     tempBools[itemHit - soundCheck1 + 1] := not tempBools[itemHit - soundCheck1 + 1];
  183.                     GetDItem(theDlgPtr, itemHit, itemT, itemH, tempRect);
  184.                     if (tempBools[itemHit - soundCheck1 + 1]) then
  185.                         SetCtlValue(ControlHandle(itemH), 1)
  186.                     else
  187.                         SetCtlValue(ControlHandle(itemH), 0);
  188.                 end;
  189.  
  190.         until exitDialog;
  191.  
  192.         DisposDialog(theDlgPtr);
  193.     end;
  194.  
  195. {=================================}
  196.  
  197.     procedure DoSpeed;
  198.         const
  199.             okayButton = 1;
  200.             cancelButton = 2;
  201.             fastRadio = 3;
  202.             slowRadio = 7;
  203.             userItem = 9;
  204.  
  205.         var
  206.             theDlgPtr: DialogPtr;
  207.             tempRect: Rect;
  208.             itemT, itemHit, tempDelay, i: Integer;
  209.             itemH: Handle;
  210.             tempStr: Str255;
  211.             exitDialog: Boolean;
  212.  
  213. {----------------}
  214.  
  215.         procedure DrawDefaultAndFrame;
  216.         begin
  217.             ForeColor(redColor);
  218.             GetDItem(theDlgPtr, userItem, itemT, itemH, tempRect);
  219.             FrameRect(tempRect);
  220.             ForeColor(blackColor);
  221.             GetDItem(theDlgPtr, okayButton, itemT, itemH, tempRect);
  222.             PenSize(3, 3);
  223.             InsetRect(tempRect, -4, -4);
  224.             FrameRoundRect(tempRect, 16, 16);
  225.             PenNormal;
  226.         end;
  227.  
  228. {----------------}
  229.  
  230.     begin
  231.         CenterDialog(speedDialID);
  232.         theDlgPtr := GetNewDialog(speedDialID, nil, Pointer(-1));
  233.         ShowWindow(theDlgPtr);
  234.         SetPort(GrafPtr(theDlgPtr));
  235.  
  236.         tempDelay := delayTime;
  237.         GetDItem(theDlgPtr, tempDelay + fastRadio, itemT, itemH, tempRect);
  238.         SetCtlValue(ControlHandle(itemH), 1);
  239.  
  240.         exitDialog := FALSE;
  241.         DrawDefaultAndFrame;
  242.  
  243.         repeat
  244.             ModalDialog(nil, itemHit);
  245.  
  246.             if (ItemHit = okayButton) then
  247.                 begin
  248.                     exitDialog := TRUE;
  249.                     delayTime := tempDelay;
  250.                 end;
  251.  
  252.             if (ItemHit = cancelButton) then
  253.                 exitDialog := TRUE;
  254.  
  255.             if ((itemHit >= fastRadio) or (itemHit <= slowRadio)) then
  256.                 begin
  257.                     for i := fastRadio to slowRadio do
  258.                         begin
  259.                             GetDItem(theDlgPtr, i, itemT, itemH, tempRect);
  260.                             SetCtlValue(ControlHandle(itemH), 0);
  261.                         end;
  262.  
  263.                     GetDItem(theDlgPtr, itemHit, itemT, itemH, tempRect);
  264.                     SetCtlValue(ControlHandle(itemH), 1);
  265.  
  266.                     tempDelay := itemHit - fastRadio;
  267.                 end;
  268.  
  269.         until exitDialog;
  270.  
  271.         DisposDialog(theDlgPtr);
  272.     end;
  273.  
  274. {=================================}
  275.  
  276.     procedure DoHelpPlay;
  277.         const
  278.             okayButton = 1;
  279.  
  280.         var
  281.             theDlgPtr: DialogPtr;
  282.             tempRect: Rect;
  283.             itemT, itemHit: Integer;
  284.             itemH: Handle;
  285.  
  286. {----------------}
  287.  
  288.         procedure DrawDefault;
  289.         begin
  290.             GetDItem(theDlgPtr, okayButton, itemT, itemH, tempRect);
  291.             PenSize(3, 3);
  292.             InsetRect(tempRect, -4, -4);
  293.             FrameRoundRect(tempRect, 16, 16);
  294.             PenSize(1, 1);
  295.         end;
  296.  
  297. {----------------}
  298.  
  299.     begin
  300.         CenterDialog(helpPlayDialID);
  301.         theDlgPtr := GetNewDialog(helpPlayDialID, nil, Pointer(-1));
  302.         ShowWindow(theDlgPtr);
  303.         SetPort(GrafPtr(theDlgPtr));
  304.         DrawDefault;
  305.  
  306.         repeat
  307.             ModalDialog(nil, itemHit);
  308.         until (ItemHit = okayButton);
  309.  
  310.         DisposDialog(theDlgPtr);
  311.     end;
  312.  
  313. {=================================}
  314.  
  315.     procedure DoHelpRules;
  316.         const
  317.             okayButton = 1;
  318.  
  319.         var
  320.             theDlgPtr: DialogPtr;
  321.             tempRect: Rect;
  322.             itemT, itemHit: Integer;
  323.             itemH: Handle;
  324.  
  325. {----------------}
  326.  
  327.         procedure DrawDefault;
  328.         begin
  329.             GetDItem(theDlgPtr, okayButton, itemT, itemH, tempRect);
  330.             PenSize(3, 3);
  331.             InsetRect(tempRect, -4, -4);
  332.             FrameRoundRect(tempRect, 16, 16);
  333.             PenSize(1, 1);
  334.         end;
  335.  
  336. {----------------}
  337.  
  338.     begin
  339.         CenterDialog(helpRulesDialID);
  340.         theDlgPtr := GetNewDialog(helpRulesDialID, nil, Pointer(-1));
  341.         ShowWindow(theDlgPtr);
  342.         SetPort(GrafPtr(theDlgPtr));
  343.         DrawDefault;
  344.  
  345.         repeat
  346.             ModalDialog(nil, itemHit);
  347.         until (ItemHit = okayButton);
  348.  
  349.         DisposDialog(theDlgPtr);
  350.     end;
  351.  
  352. {=================================}
  353.  
  354.     function idleFilter (theDialog: DialogPtr; var theEvent: EventRecord; var itemHit: integer): boolean;
  355.         var
  356.             mousePt: Point;
  357.     begin
  358.         idleFilter := FALSE;
  359.         if ((theEvent.what = KeyDown) and (BitAnd(theEvent.message, CharCodeMask) = 13)) then
  360.             begin
  361.                 itemHit := 1;
  362.                 idleFilter := TRUE;
  363.             end;
  364.  
  365.         if (StillDown) then
  366.             begin
  367.                 GetMouse(mousePt);
  368.                 if (PtInRect(mousePt, upRect)) then
  369.                     begin
  370.                         itemHit := 8;
  371.                         idleFilter := TRUE;
  372.                     end;
  373.                 if (PtInRect(mousePt, dnRect)) then
  374.                     begin
  375.                         itemHit := 9;
  376.                         idleFilter := TRUE;
  377.                     end;
  378.             end;
  379.     end;
  380.  
  381. {=================================}
  382.  
  383.     procedure DoPhysics;
  384.         const
  385.             okayButton = 1;
  386.             cancelButton = 2;
  387.             defaultButton = 3;
  388.             noFricRadio = 4;
  389.             strongFricRadio = 7;
  390.             upGravIcon = 8;
  391.             downGravIcon = 9;
  392.             gravStat = 10;
  393.             gravIcon = 11;
  394.             userItem = 13;
  395.             userItem2 = 14;
  396.             userItem3 = 15;
  397.  
  398.         var
  399.             theDlgPtr: DialogPtr;
  400.             tempRect: Rect;
  401.             itemT, itemHit, tempGrav, tempFrict: Integer;
  402.             itemH: Handle;
  403.             exitDialog: Boolean;
  404.  
  405. {----------------}
  406.  
  407.         procedure DrawDefaultAndFrame;
  408.         begin
  409.             ForeColor(redColor);
  410.             GetDItem(theDlgPtr, userItem, itemT, itemH, tempRect);
  411.             FrameRect(tempRect);
  412.             GetDItem(theDlgPtr, userItem2, itemT, itemH, tempRect);
  413.             FrameRect(tempRect);
  414.             GetDItem(theDlgPtr, userItem3, itemT, itemH, tempRect);
  415.             FrameRect(tempRect);
  416.             ForeColor(blackColor);
  417.             GetDItem(theDlgPtr, okayButton, itemT, itemH, tempRect);
  418.             PenSize(3, 3);
  419.             InsetRect(tempRect, -4, -4);
  420.             FrameRoundRect(tempRect, 16, 16);
  421.             PenNormal;
  422.         end;
  423.  
  424. {----------------}
  425.  
  426.         procedure UpdateGrav;
  427.             var
  428.                 whichIcon: Integer;
  429.                 tempStr: Str255;
  430.                 icnHand: Handle;
  431.                 cicnHand: CIconHandle;
  432.         begin
  433.             NumToString(tempGrav, tempStr);
  434.             GetDItem(theDlgPtr, gravStat, itemT, itemH, tempRect);
  435.             SetIText(itemH, tempStr);
  436.  
  437.             if (tempGrav = 0) then
  438.                 whichIcon := 138
  439.             else
  440.                 whichIcon := ((tempGrav - 1) div 20) + 139;
  441.  
  442.             GetDItem(theDlgPtr, gravIcon, itemT, itemH, tempRect);
  443.             if (inColor) then
  444.                 begin
  445.                     cicnHand := GetCIcon(whichIcon);
  446.                     if (cicnHand <> nil) then
  447.                         begin
  448.                             PlotCIcon(tempRect, cicnHand);
  449.                             DisposCIcon(cicnHand);
  450.                         end;
  451.                 end
  452.             else
  453.                 begin
  454.                     icnHand := GetIcon(whichIcon);
  455.                     if (icnHand <> nil) then
  456.                         PlotIcon(tempRect, icnHand);
  457.                 end;
  458.         end;
  459.  
  460. {----------------}
  461.  
  462.         procedure UpdateRadios;
  463.             var
  464.                 i: Integer;
  465.         begin
  466.             for i := noFricRadio to strongFricRadio do
  467.                 begin
  468.                     GetDItem(theDlgPtr, i, itemT, itemH, tempRect);
  469.                     SetCtlValue(ControlHandle(itemH), 0);
  470.                 end;
  471.             GetDItem(theDlgPtr, tempFrict + noFricRadio, itemT, itemH, tempRect);
  472.             SetCtlValue(ControlHandle(itemH), 1);
  473.         end;
  474.  
  475. {----------------}
  476.  
  477.     begin
  478.         CenterDialog(physicsDialID);
  479.         theDlgPtr := GetNewDialog(physicsDialID, nil, Pointer(-1));
  480.         ShowWindow(theDlgPtr);
  481.         SetPort(GrafPtr(theDlgPtr));
  482.  
  483.         tempFrict := frictState;
  484.         tempGrav := mouseConst - 50;
  485.  
  486.         GetDItem(theDlgPtr, upGravIcon, itemT, itemH, upRect);
  487.         GetDItem(theDlgPtr, downGravIcon, itemT, itemH, dnRect);
  488.  
  489.         UpdateRadios;
  490.         UpdateGrav;
  491.  
  492.         exitDialog := FALSE;
  493.         DrawDefaultAndFrame;
  494.  
  495.         repeat
  496.             ModalDialog(@idleFilter, itemHit);
  497.  
  498.             if (itemHit = okayButton) then
  499.                 begin
  500.                     mouseConst := tempGrav + 50;
  501.                     if (mouseConst > 150) then
  502.                         mouseConst := 150;
  503.                     if (mouseConst < 50) then
  504.                         mouseConst := 50;
  505.  
  506.                     frictState := tempFrict;
  507.                     if (frictState > 3) then
  508.                         frictState := 3;
  509.                     if (frictState < 0) then
  510.                         frictState := 0;
  511.  
  512.                     exitDialog := TRUE;
  513.                 end;
  514.  
  515.             if (itemHit = cancelButton) then
  516.                 exitDialog := TRUE;
  517.  
  518.             if (itemHit = defaultButton) then
  519.                 begin
  520.                     tempFrict := normalFriction;
  521.                     tempGrav := 50;
  522.                     UpdateRadios;
  523.                     UpdateGrav;
  524.                 end;
  525.  
  526.             if ((itemHit >= noFricRadio) and (itemHit <= strongFricRadio)) then
  527.                 begin
  528.                     tempFrict := itemHit - noFricRadio;
  529.                     UpdateRadios;
  530.                 end;
  531.  
  532.             if ((itemHit = upGravIcon) and (tempGrav < 100)) then
  533.                 begin
  534.                     GetDItem(theDlgPtr, upGravIcon, itemT, itemH, tempRect);
  535.                     InvertRect(tempRect);
  536.                     tempGrav := tempGrav + 1;
  537.                     UpdateGrav;
  538.                     GetDItem(theDlgPtr, upGravIcon, itemT, itemH, tempRect);
  539.                     InvertRect(tempRect);
  540.                 end;
  541.  
  542.             if ((itemHit = downGravIcon) and (tempGrav > 0)) then
  543.                 begin
  544.                     GetDItem(theDlgPtr, downGravIcon, itemT, itemH, tempRect);
  545.                     InvertRect(tempRect);
  546.                     tempGrav := tempGrav - 1;
  547.                     UpdateGrav;
  548.                     GetDItem(theDlgPtr, downGravIcon, itemT, itemH, tempRect);
  549.                     InvertRect(tempRect);
  550.                 end;
  551.  
  552.         until exitDialog;
  553.  
  554.         DisposDialog(theDlgPtr);
  555.     end;
  556.  
  557. {=================================}
  558.  
  559. end.